package com.flex.core.validate.impl;

import com.flex.core.validate.AbstractValidator;

/**
 * 字符串长度验证器
 * 
 * @author radio
 * 
 */
public class StringValidator extends AbstractValidator {

	/**
	 * 验证字符串的长度在min和max之间，如果字符串中有中文则会在抽象父类中将汉字转成2个长度
	 */
	protected String doValidate() {
		String msg = "";
		String value = (String) formateValue();
		int length = value.trim().length();
		int max = Integer.valueOf(getValidation().max());
		int min = Integer.valueOf(getValidation().min());
		if ((min > -1) && (length < min)) {
			msg = getValidation().message();
		} else if ((max > -1) && (length > max)) {
			msg = getValidation().message();
		}
		return msg;
	}

}
